Fix ParallelExecutor crash when Parallel called from within module forward()#9104
Open
LukeDevs wants to merge 3 commits into
Open
Fix ParallelExecutor crash when Parallel called from within module forward()#9104LukeDevs wants to merge 3 commits into
LukeDevs wants to merge 3 commits into
Conversation
TomeHirata
reviewed
Dec 4, 2025
| index, outcome = f.result() | ||
| except Exception: | ||
| pass | ||
| logger.error(f"Worker failed: {e}") |
Collaborator
There was a problem hiding this comment.
This is not really helpful since we catch exceptions by wrapping the original function in _wrap_function
TomeHirata
reviewed
Dec 4, 2025
| if parent_overrides.get("usage_tracker"): | ||
| # Usage tracker needs to be deep copied across threads so that each thread tracks its own usage | ||
| thread_local_overrides.overrides["usage_tracker"] = copy.deepcopy(parent_overrides["usage_tracker"]) | ||
| new_overrides["usage_tracker"] = copy.deepcopy(parent_overrides["usage_tracker"]) |
Collaborator
There was a problem hiding this comment.
Looks reasonable, can we keep the comment? And also can you add a test?
Author
There was a problem hiding this comment.
@TomeHirata Added the comment back in directly above the deep copy.
Author
|
@TomeHirata. Implemented a unit test as requested. Tried to use the existing tests as reference. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
## Summary
Fixes a bug where
dspy.Parallelsilently returnsNonefor all tasks when called from within a module'sforward()method while MLflow autologging is enabled.**## Problem
When using
mlflow.dspy.autolog(), callingdspy.Parallelfrom inside a module'sforward()method causes all results to silently returnNone.The root cause is twofold:
1. Incorrect ContextVar access in
parallelizer.py(line 95)thread_local_overridesis aContextVar, which requires.get()and.set()methods for access. The existing code incorrectly attempts to access an.overridesattribute directly:This raises
AttributeError: '_contextvars.ContextVar' object has no attribute 'overrides'.The bug only manifests when
usage_trackeris present in the parent context, which occurs when MLflow autologging is enabled.2. Silent exception handling (line ~155)
Worker exceptions are caught and silently discarded:
This masked the underlying
AttributeError.**## Solution
1. Restructured ContextVar access to build the complete overrides dictionary before setting:
2. Added error logging for worker failures:
**## Reproduction